/************************************************************************************
* TrackBrowser.h                                                                        *
*                                                                                   *
* Copyright (C) 2011 Varuna L Amachi                                              *
*                                                                                   *
* This program is free software; you can redistribute it and/or modify              *
* it under the terms of the GNU General Public License as published by              *
* the Free Software Foundation; either version 2 of the License, or any             *
* later version.                                                                    *
*                                                                                   *
* This program is distributed in the hope that it will be useful, but               *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY        *
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for       *
* more details. You should have received a copy of the GNU General Public           *
* License along with this program; if not, write to the Free Software Foundation,   *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                       *
*                                                                                   *
*************************************************************************************/ 

#ifndef TRACKBROWSER_H
#define TRACKBROWSER_H

#include "interfaces/IPlayerListener.h"
#include "common/YampComponent.h"
#include "AlbumModel.h"
#include "ArtistModel.h"
#include "collector_common/SimpleCollectionView.h"
#include "collector_common/PartialCollectionModel.h"
#include "widgets/SearchBox.h"

#include <QTreeView>


class TrackBrowser : public YampComponent,
        public IPlayerListener
{
    Q_OBJECT

    QTreeView               *m_artistView;
    QTreeView               *m_albumView;
    SimpleCollectionView    *m_trackView;
    ArtistSortFilterModel   *m_artistProxy;
    AlbumSortFilterModel    *m_albumProxy;
    SearchBox               *m_artistFilter;
//    SearchBox               *m_albumFilter;

    ArtistModel          *m_artistModel;
    AlbumModel           *m_albumModel;
    PartialCollectionModel *m_trackModel;

    QAction *m_actAddArtist;
    QAction *m_actAddAlbum;
    QAction *m_actAddTracks;

    void setupUi();
    void setupActions();
    void setupConnections();
    void setupStyle();

    void selectRow(QTreeView *view, int row);

public:
    explicit TrackBrowser(Yamp::YContext *context, QWidget *parent = 0);
    virtual ~TrackBrowser();
    QString name();
    void playStarted(MediaItem* item);
    void finished(MediaItem* item){} //Ignored
    void ratingChanged(MediaItem* item, MediaRating rating);

private slots:
    void onArtistSelected();
    void onAlbumSelected();
    void onTrackSelected(CollectorItem *item);
    void applyFilter();

    void onAddArtistToPlaylist();
    void onAddAlbumToPlaylist();
    void onAddTracksToPlaylist();

    void allModelClean();
    void allModelUpdate();
};

#endif // TRACKBROWSER_H
